<template>
  <div class="app-container">
    <el-alert
      title="新建链接"
      type="success"
      effect="dark"
      :closable="false"
    />
    <el-form ref="form" :model="form" label-width="300px" class="form-container">
      <el-form-item label="子客户密钥appKey" required>
        <el-input v-model="form.appKey" />
      </el-form-item>
      <el-form-item label="子客户token" required>
        <el-input v-model="form.token" />
      </el-form-item>
      <el-form-item label="转化因子" required>
        <el-input v-model="form.transform" />
      </el-form-item>
      <el-form-item label="回传事件类型" required>
        <el-select v-model="form.event_typeStr" placeholder="活动区域">
          <el-option label="唤醒app" value="wake" />
          <el-option label="收藏" value="favorite" />
          <el-option label="下载" value="download" />
          <el-option label="安装" value="install" />
          <el-option label="注册" value="register" />
          <el-option label="激活" value="active" />
          <el-option label="登录" value="login" />
          <el-option label="付费" value="pay" />
          <el-option label="到访" value="visit" />

        </el-select>
      </el-form-item>
      <el-form-item label="是否深度转化" required>
        <el-select v-model="form.deep_convStr" placeholder="活动区域">
          <el-option label="单目标" value="0" />
          <el-option label="双目标" value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="闲鱼渠道参数">
        <el-input v-model="form.lid" />
      </el-form-item>
      <el-form-item label="闲鱼手机端链接(安卓或IOS)">
        <el-input v-model="form.xianyuUrl" />
      </el-form-item>
      <el-form-item label="闲鱼上报">
        <el-select v-model="form.chooseStr" placeholder="活动区域">
          <el-option label="曝光上报" value="0" />
          <el-option label="点击上报" value="1" />
          <el-option label="无" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('form')">立即创建</el-button>
        <el-button @click="onCancel('form')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { youkuCreateEffpoint } from '@/api/youku'
import { Message } from 'element-ui'
export default {
  data() {
    return {
      form: {
        appKey: '',
        token: '',
        transform: '',
        event_typeStr: '',
        deep_convStr: '',
        lid: '',
        xianyuUrl: '',
        chooseStr: ''
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          youkuCreateEffpoint(this.form).then(response => {
            // console.log(response)
          }).catch(() => {
            Message({
              message: '访问链接不存在！',
              type: 'error',
              duration: 5 * 1000
            })
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}

.app-container{
  padding: 30px;
}

.form-container{
  margin-top: 20px;
}
</style>

